package cn.liangent.travlib;

import static cn.liangent.travlib.util.Utilities.*;
import java.io.*;

public class Field extends Building {
	
	public Field(Village village, int id) {
		super(village, id);
		if (id < 1 || id > 18) {
			throw new IllegalArgumentException();
		}
	}

	public int getProduction() throws IOException, HttpException, AuthenticationException, BadPageException {
		String pgsrc = getBuildingPage();
		String sprod = find(pgsrc, "\\Q<td><b>\\E(\\d+)\\Q</b>\\E");
		int prod;
		try {
			prod = Integer.parseInt(sprod);
		} catch (Exception ex) {
			throw new BadPageException(ex);
		}
		if (prod <= 0) {
			throw new BadPageException("production <= 0");
		}
		return prod;
	}
}
